<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<!--[if lt IE 9]
<script type="text/javascript" src="<%=basePath%>resources/lib/html5.js"></script>
<script type="text/javascript" src="<%=basePath%>resources/lib/respond.min.js"></script>
<script type="text/javascript" src="<%=basePath%>resources/lib/PIE_IE678.js"></script>
<![endif]-->
	<link rel="stylesheet" type="text/css" href="<%=basePath%>resources/static/h-ui/css/H-ui.min.css" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>resources/static/h-ui.admin/css/H-ui.admin.css" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>resources/lib/Hui-iconfont/1.0.7/iconfont.css" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>resources/lib/icheck/icheck.css" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>resources/static/h-ui.admin/skin/default/skin.css" id="skin" />
	<link rel="stylesheet" type="text/css" href="<%=basePath%>resources/lib/laypage/1.2/skin/laypage.css" />
	<!--[if IE 6]>
	<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
	<script>DD_belatedPNG.fix('*');</script>
	<![endif]-->
	<title>交易列表</title>
</head>
<body>
<div class="page-container">

	<form action="<%=basePath%>trade/tradeCount" method="get" class="form form-horizontal">
		<div class="text-c"> 日期：
			<input type="text" onfocus="WdatePicker()" id="datemin" name="datemin" value="${object.datemin}" class="input-text Wdate" style="width:160px;">
			-
			<input type="text" onfocus="WdatePicker()" id="datemax" name="datemax" value="${object.datemax}" class="input-text Wdate" style="width:160px;">
			状态：
			<select id="tradeStatus" name="tradeStatus" class="select" style="width: 80px">
				<option id="-1" value="">所有状态</option>
				<option id="1" value="1" <c:if test="${object.tradeStatus==1}">selected='selected'</c:if> >正在审核</option>
				<option id="2" value="2" <c:if test="${object.tradeStatus==2}">selected='selected'</c:if> >正在代练</option>
				<option id="3" value="3" <c:if test="${object.tradeStatus==3}">selected='selected'</c:if> >等待验收</option>
				<option id="4" value="4" <c:if test="${object.tradeStatus==4}">selected='selected'</c:if> >等待结算</option>
				<option id="5" value="5" <c:if test="${object.tradeStatus==5}">selected='selected'</c:if> >已经结算</option>
				<option id="6" value="6" <c:if test="${object.tradeStatus==6}">selected='selected'</c:if> >订单异常</option>
				<option id="7" value="7" <c:if test="${object.tradeStatus==7}">selected='selected'</c:if> >审核失败</option>
				<option id="8" value="8" <c:if test="${object.tradeStatus==8}">selected='selected'</c:if> >验证失败</option>
				<option id="9" value="9" <c:if test="${object.tradeStatus==9}">selected='selected'</c:if> >等待接手</option>
			</select>
			游戏：
			<select id="gameSelect" name="gameId" class="select" style="width: 80px"></select>
			<input type="text" class="input-text" style="width:130px" placeholder="可输交易号" name="tradeId" value="${object.tradeId}">
			<input type="text" class="input-text" style="width:130px" placeholder="可输打手号" name="userId" value="${object.userId}">
			<button type="submit" class="btn btn-primary radius" name=""><i class="Hui-iconfont">&#xe665;</i> 搜交易</button>
			<c:if test="${empty  object.gameId}">
				<button type="button" class="btn btn-primary radius" name=""
						onclick="window.location.href='<%=basePath%>trade/exportData?datemin=${object.datemin}&datemax=${object.datemax}&tradeStatus=${object.tradeStatus}&tradeId=${object.tradeId}&userId=${object.userId}&gameId=-1'">
					<i class="Hui-iconfont">&#xe644;</i> 导出
				</button>
			</c:if>
			<c:if test="${not empty object.gameId}">
				<button type="button" class="btn btn-primary radius" name=""
						onclick="window.location.href='<%=basePath%>trade/exportData?datemin=${object.datemin}&datemax=${object.datemax}&tradeStatus=${object.tradeStatus}&tradeId=${object.tradeId}&userId=${object.userId}&gameId=${object.gameId}'">
					<i class="Hui-iconfont">&#xe644;</i> 导出
				</button>
			</c:if>
		</div>
	</form>
	<%--<div class="cl pd-5 bg-1 bk-gray mt-20">
		<span class="l"><a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a>
			<a href="javascript:;" onclick="member_add('添加订单','<%=basePath%>order/orderAdd','','510')" class="btn btn-primary radius">
				<i class="Hui-iconfont">&#xe600;</i> 添加订单
			</a>
		</span>
		<span class="r">共有数据：<strong>${orders.size()}</strong> 条</span> </div>
	<div class="mt-20">--%>
	<table class="table table-border table-bordered table-hover table-bg table-sort">
		<thead>
		<tr class="text-c">
			<%--<th width="25"><input type="checkbox" name="" value=""></th>--%>
			<th width="50">交易ID</th>
			<th width="50">订单编号</th>
			<th width="50">用户ID</th>
			<th width="50">打手姓名</th>
			<th width="30">游戏名称</th>
			<th width="60">区服</th>
			<c:if test="${object.gameName=='魔兽世界'}">
				<th width="35">阵营</th>
				<th width="35">职业天赋</th>
				<th width="35">装等</th>
			</c:if>
			<th width="150">代练内容</th>
			<th width="20">结算价</th>
			<th width="80">验收时间</th>
			<th width="50">状态</th>
			<%--<th width="50">操作</th>--%>
		</tr>
		</thead>
		<tbody>
		<c:forEach items="${trades}" var="trade">
			<tr class="text-c">
					<%--<td><input type="checkbox" value="${order.id}" name=""></td>--%>
				<td><u style="cursor:pointer" class="text-primary" onclick="member_show('交易详情','<%=basePath%>/trade/tradeShow?id=${trade.id}','10001','660','500')">${trade.id}</u></td>
				<td><u style="cursor:pointer" class="text-primary" onclick="member_show('订单详情','<%=basePath%>/order/orderShow?id=${trade.orderId}','10001','660','500')">${trade.orderId}</u></td>
				<td><u style="cursor:pointer" class="text-primary" onclick="member_show('用户详情','<%=basePath%>/user/memberShow?userId=${trade.userId}','10001','660','500')">${trade.userId}</u></td>
				<td>${trade.userName}</td>
				<td>${trade.gameName}</td>
				<td>${trade.serviceArea}</td>
				<%--<td>${trade.camp}</td>
				<td>${trade.professionalTalent}</td>
				<td>${trade.install}</td>--%>
				<c:if test="${object.gameName=='魔兽世界'}">
					<td>${trade.camp}</td>
					<td>${trade.professionalTalent}</td>
					<td>${trade.install}</td>
				</c:if>
				<td>${trade.content}</td>
				<td>${trade.settlePrice}</td>
				<td>${trade.createTimeString}</td>
				<td class="td-status">
					<c:if test="${trade.status==2||trade.status==5}">
						<span class="label label-success radius">${trade.statusString}</span>
					</c:if>
					<c:if test="${trade.status==1||trade.status==3||trade.status==4||trade.status==9}">
						<span class="label label-warning radius">${trade.statusString}</span>
					</c:if>
					<c:if test="${trade.status==6||trade.status==7||trade.status==8}">
						<span class="label label-danger radius">${trade.statusString}</span>
					</c:if>
				</td>
				<%--<td class="td-manage">
					&lt;%&ndash;管理员审核交易  审核&ndash;%&gt;
					<c:if test="${userSession.type == 1 || trade.status==1}">
					<a style="text-decoration:none" onClick="trade_shenhe(this,${trade.id})" href="javascript:;" title="审核">审核</a>
					</c:if>

					&lt;%&ndash;管理员审核交易  验收&ndash;%&gt;
					<c:if test="${userSession.type == 1 || trade.status==3}">
					<a style="text-decoration:none" onClick="trade_check(this,${trade.id})" href="javascript:;" title="验收(点击链接可以查看代练详情)">验收</a>
					</c:if>

					&lt;%&ndash;管理员审核交易  结算&ndash;%&gt;
					<c:if test="${userSession.type == 1 || trade.status==4}">
					<a style="text-decoration:none" onClick="trade_jiesuan(this,${trade.id})" href="javascript:;" title="结算">结算</a>
					</c:if>

					&lt;%&ndash;打手可以撤销交易,状态必须是 1 审核中 7 审核不通过&ndash;%&gt;
					<c:if test="${userSession.type == 3 && (trade.status==1||trade.status==7)}"></c:if>
					<a title="撤销" href="javascript:;" onclick="trade_del(this,${trade.id})" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>


					&lt;%&ndash;打手提交订单,或者上报异常单&ndash;%&gt;
					<c:if test="${userSession.type == 3 && (trade.status==2)}"></c:if>
					<a title="提交或异常" data-title="提交或异常" href="<%=basePath%>trade/tradeCommit?tradeId=${trade.id}" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe615;</i></a>

					&lt;%&ndash;指派订单,打手选择同意或者拒绝&ndash;%&gt;
					<c:if test="${userSession.type == 3 && (trade.status==9)}"></c:if>
					<a style="text-decoration:none" onClick="trade_agree(this,${trade.id})" href="javascript:;" title="接手">接手</a>


				</td>--%>
			</tr>
		</c:forEach>
		</tbody>
	</table>
</div>
</div>
<script type="text/javascript" src="<%=basePath%>resources/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="<%=basePath%>resources/lib/layer/2.1/layer.js"></script>
<script type="text/javascript" src="<%=basePath%>resources/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="<%=basePath%>resources/lib/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="<%=basePath%>resources/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="<%=basePath%>resources/static/h-ui/js/H-ui.js"></script>
<script type="text/javascript" src="<%=basePath%>resources/static/h-ui.admin/js/H-ui.admin.js"></script>
<script type="text/javascript">
	$(function(){
		$('.table-sort').dataTable({
			"aaSorting": [[ 0, "desc" ]],//默认第几个排序
			"bStateSave": true,//状态保存
			"aoColumnDefs": [
				//{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
				{"orderable":false,"aTargets":[0,8,9]}// 制定列不参与排序
			]
		});
		$('.table-sort tbody').on( 'click', 'tr', function () {
			if ( $(this).hasClass('selected') ) {
				$(this).removeClass('selected');
			}
			else {
				table.$('tr.selected').removeClass('selected');
				$(this).addClass('selected');
			}
		});
	});
	$.ajax({
		type: "get",
		url: "<%=basePath%>game/getGamesNoCount",
		async: false,
		cache: false,
		success: function (data) {
			$("#gameSelect").empty();
			$("#gameSelect").append("<option value='-1'>" + "所有游戏" + "</option>");
			for(var i =0;i<data.length;i++){
				$("#gameSelect").append("<option value=" + data[i].id + ">" + data[i].name + "</option>");
			}
			$("#gameSelect").find("option[value='${object.gameId}']").attr("selected",true);
		}
	});
	/*确认要撤销交易单吗*/
	function trade_del(obj,id){
		layer.confirm('确认要撤销交易单吗？',function(index){
			$.ajax({
				url:"<%=basePath%>trade/delTrade",
				data:{"tradeId":id},
				type:"post",
				cache: false,
				success:function (data) {
					if(data.code==0){
						$(obj).parents("tr").remove();
						layer.msg('已撤销!',{icon: 6,time:2000});
					}else {
						$(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">'+data.message+'</span>');
						$(obj).remove();
						layer.msg(data.message,{icon: 5,time:2000});
					}
				}
			});

		});
	}


	/*交易结算*/
	function trade_jiesuan(obj,id){
		layer.confirm('确认已经给打手打过款了吗？',function(index){
			$.ajax({
				url:"<%=basePath%>trade/settlerTrade",
				data:{"tradeId":id,"tradeStatus":4},
				type:"post",
				cache: false,
				success:function (data) {
					if(data.code==0){
						$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="#" href="javascript:;" title="已结算"><i class="Hui-iconfont">&#xe631;</i></a>');
						$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已结算</span>');
						$(obj).remove();
						layer.msg(data.message,{icon:6,time:2000});
					}else {
						layer.msg(data.message,{icon:5,time:2000});
					}
				}
			});
		});
	}
	/*审核交易*/
	function trade_shenhe(obj,id){
		layer.confirm('审核交易？审核通过后将直接变成代练中', {
					btn: ['通过','不通过','取消'],
					shade: false,
					closeBtn: 0
				},
				function(){
					$.ajax({
						url:"<%=basePath%>trade/setTradeWork",
						data:{"tradeId":id,"tradeStatus":2},
						type:"post",
						cache: false,
						success:function (data) {
							if(data.code==0){
								/*$(obj).parents("tr").find(".td-manage").prepend('<a class="c-primary" onClick="trade_shenhe(this,id)" href="javascript:;" title="已通过">已通过</a>');
								*/
								$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">代练中</span>');
								$(obj).remove();
								layer.msg('已通过', {icon:6,time:2000});
							}else {
								layer.msg(data.message,{icon:5,time:2000});
							}
						}
					});
				},
				function(){
					$.ajax({
						url:"<%=basePath%>trade/setTradeCheckToNotPass",
						data:{"tradeId":id,"tradeStatus":7},
						type:"post",
						cache: false,
						success:function (data) {
							if(data.code==0){
								/*$(obj).parents("tr").find(".td-manage").prepend('<a class="c-primary" onClick="trade_shenhe(this,id)" href="javascript:;" title="不通过">不通过</a>');
								*/
								$(obj).parents("tr").find(".td-status").html('<span class="label label-danger radius">不通过</span>');
								$(obj).remove();
								layer.msg('不通过', {icon:5,time:2000});
							}else {
								layer.msg(data.message,{icon:5,time:2000});
							}
						}
					});
				});
	}
	/*验收交易*/
	function trade_check(obj,id){
		layer.confirm('验收交易？代练的不错,验收可以点击表格中的交易Id', {
					btn: ['通过','不通过','取消'],
					shade: false,
					closeBtn: 0
				},
				function(){
					$.ajax({
						url:"<%=basePath%>trade/checkThrough",
						data:{"tradeId":id,"tradeStatus":4},
						type:"post",
						cache: false,
						success:function (data) {
							if(data.code==0){
								/*$(obj).parents("tr").find(".td-manage").prepend('<a class="c-primary" onClick="trade_shenhe(this,id)" href="javascript:;" title="已通过">已通过</a>');
								 */
								$(obj).parents("tr").find(".td-status").html('<span class="label label-warning radius">待结算</span>');
								$(obj).remove();
								layer.msg('已通过', {icon:6,time:2000});
							}else {
								layer.msg(data.message,{icon:5,time:2000});
							}
						}
					});
				},
				function(){
					$.ajax({
						url:"<%=basePath%>trade/setTradeCheckToNotPass",
						data:{"tradeId":id,"tradeStatus":6},
						type:"post",
						cache: false,
						success:function (data) {
							if(data.code==0){
								$(obj).parents("tr").find(".td-manage").prepend('<a class="c-primary" onClick="trade_check(this,id)" href="javascript:;" title="验收">验收</a>');
								$(obj).parents("tr").find(".td-status").html('<span class="label label-danger radius">验收不通过</span>');
								$(obj).remove();
								layer.msg('验收不通过', {icon:6,time:2000});
							}else {
								layer.msg(data.message,{icon:5,time:2000});
							}
						}
					});
				});
	}
	/*同意指派*/
	function trade_agree(obj,id){
		layer.confirm('同意接手？同意将变成代练中,拒接了其他打手可以申请', {
					btn: ['同意','拒接','取消'],
					shade: false,
					closeBtn: 0
				},
				function(){
					$.ajax({
						url:"<%=basePath%>trade/tradeAgree",
						data:{"tradeId":id,"agree":1},
						type:"post",
						cache: false,
						success:function (data) {
							if(data.code==0){
								$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">代练中</span>');
								$(obj).remove();
								layer.msg('已同意', {icon:6,time:2000});
							}else {
								layer.msg(data.message,{icon:5,time:2000});
							}
						}
					});
				},
				function(){
					$.ajax({
						url:"<%=basePath%>trade/tradeAgree",
						data:{"tradeId":id,"agree":0},
						type:"post",
						cache: false,
						success:function (data) {
							if(data.code==0){
								$(obj).parents("tr").remove();
								layer.msg('拒接成功', {icon:5,time:2000});
							}else {
								layer.msg(data.message,{icon:5,time:2000});
							}
						}
					});
				});
	}
	/*密码-修改*/
	function change_password(title,url,id,w,h){
		layer_show(title,url,w,h);
	}

	/*用户-删除*/
	function order_del(obj,id){
		layer.confirm('确认要删除吗？',function(index){
			$.ajax({
				url:"<%=basePath%>order/deleteOrder",
				data:{"orderId":id,"orderType":7},
				type:"post",
				cache: false,
				success:function (data) {
					if(data.code==0){
						$(obj).parents("tr").remove();
						layer.msg('已删除!',{icon:1,time:2000});
					}else {
						layer.msg(data.message,{icon:5,time:2000});
					}
				}
			});

		});
	}
	/*用户-查看*/
	function member_show(title,url,id,w,h){
		layer_show(title,url,w,h);
	}
</script>
</body>
</html>